﻿#region Using Directives

    using System;

    using MarketPulse.Web.Helpers.Base;

#endregion

namespace MarketPulse.Web.Helpers
{
    /// <summary>
    /// This class represents a set of properties persisted using cookies.
    /// </summary>
    public class CookieManager : CookieManagerBase
    {
        #region Properties

            /// <summary>
            /// A property to store a language setting, persisted for 7 days.
            /// </summary>
            [Cookie(7d, Name = "Language")]
            public static string Language
            {
                get { return GetCookieValue(typeof(CookieManager).GetProperty("Language")); }
                set { SetCookieValue(typeof(CookieManager).GetProperty("Language"), value); }
            }

            /// <summary>
            /// A property to store a UserGUID, persisted for 1 year.
            /// </summary>
            [Cookie(365d, Name = "UserGUID")]
            public static Nullable<Guid> UserGUID
            {
                get
                {
                    Guid returnValue = Guid.Empty;
                    Guid.TryParse(GetCookieValue(typeof(CookieManager).GetProperty("UserGUID")), out returnValue); 
                    return returnValue != Guid.Empty ? (Nullable<Guid>)returnValue : null; // Just some jiggery to make it strongly-typed.
                }
                set { SetCookieValue(typeof(CookieManager).GetProperty("UserGUID"), value.ToString()); }
            }

            /// <summary>
            /// A property to store a UserHash, persisted for 1 year.
            /// </summary>
            [Cookie(365d, Name = "UserHash")]
            public static string UserKey
            {
                get { return GetCookieValue(typeof(CookieManager).GetProperty("UserKey")); }
                set { SetCookieValue(typeof(CookieManager).GetProperty("UserKey"), value); }
            }

        #endregion
    }
}